<?php 
## include required files
/*******************************/
require_once '../model/membershipplan.php';
/*******************************/
## Create Objects
/*******************************/
$planObj = new Model_PLAN();
/*******************************/

if($_GET['id']!=''&& $_GET['action']=='edit') {
	$plan_id=base64_decode($_GET['id']);
	$smarty->assign('page', $_GET['page']);
	$newplanArray=$planObj->getPlanDetailsById($plan_id);
	$smarty->assign('newplanArray', $newplanArray);
}


if(isset($_POST['editprice_btn'])) 
{


	//print_R($var_submenu_content);die();
	## apply PHP validation for required filed
	if($_POST['name']!= '') 
	{
		$planArray = array();		
		extract($_POST);			
		$planArray['name']   = return_post_value($name);
		$planArray['month']   = return_post_value($month);
		//$planArray['freeleads']   = return_post_value($freeleads);
		$planArray['leads'] = return_post_value($leads);
		$planArray['price']      = return_post_value($price);
		$planObj->editPlanById($planArray,$_POST['plan_id']);
		$_SESSION['msg']="<div class='success_msg'><span>Plan updated successfully!</span></div>";
		header('location:'.SITE_URL.'/admin/home.php?q=plan&page='.$_POST['page']);
		exit;
		
	} else {// php validation else
		$_SESSION['msg']="<div class='error_msg'><span> Plan name can't be blank</span></div>";
	}
	// main if closed
}

## Assign success or error msg to smarty variable and unset session variable
if(trim($_SESSION['msg']) != '') {
	$smarty->assign('msg', $_SESSION['msg']);
	unset($_SESSION['msg']);
}


## Set active class variable for left menu
$smarty->assign('activeclass', 'membershipplan');
$smarty->assign('mainmenu', '2');

## Unset all the objects created which are on this page
unset($planObj);

$smarty->display(TEMPLATEDIR_ADMIN. 'membershipplan/editplan.tpl');
unset($smarty);
?>